using System;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
    /**
     * Classname : HocVien
     * Version information :1.0
     * Date  :26-09-2006
     * Copyright notice : 
     */

    public class DAHocVienLV9: DbObject
    {
        protected SqlConnection connec;

        public DAHocVienLV9(SqlConnection Connection)
        {
            connec = Connection;
        }
        // return all the HocViens select Language
        // Danh cho nguoi quan tri
        public int loadDemSoHocVienLV9ByTrangThai( int TrangThaiID)
        {
            int numAffected;
            SqlParameter[] parameters = {   new SqlParameter("@TrangThaiID", SqlDbType.Int, 4) 
                                        };
            parameters[0].Value = TrangThaiID;

            // create the parameter
            DataSet dsHocVien = RunProcedure("sp_HocVienLV9_loadDemSoHocVienLV9ByTrangThai", parameters, "TB_L9", connec);
            if (dsHocVien != null && dsHocVien.Tables[0].Rows.Count > 0)
            {
                numAffected = Convert.ToInt32(dsHocVien.Tables[0].Rows[0]["Tong"].ToString());
            }
            else
            {
                numAffected = 0;
            }
            return numAffected;
        }

        public DataSet loadHocVienLV9()
        {
            // create the parameter
            DataSet dsHocVien = RunProcedure("sp_HocVienLV9_loadLV9", "TB_L9", connec);
            for (int i = 0; i < dsHocVien.Tables[0].Rows.Count; i++)
            {
                dsHocVien.Tables[0].Rows[i]["Seq"] = (i + 1).ToString();
            }
            return dsHocVien;
        }

        // return only the record with the specified ID!!!!!!!!!!!
        public DataRow loadHocVienLV9ID(int HocVienID, int LevelID)
        {
            // create the parameter
            SqlParameter[] parameters = {   new SqlParameter("@HocVienID", SqlDbType.Int, 4),
                                            new SqlParameter("@LevelID", SqlDbType.Int, 4)
                                        };
            parameters[0].Value = HocVienID;
            parameters[1].Value = LevelID;

            using (DataSet HocViens = RunProcedure("sp_HocVienLV9_loadLV9ID", parameters, "TB_L9", connec))
            {
                return HocViens.Tables[0].Rows[0];
            }
        }
	
        // add a new question
        // Them ban ghi hien hanh
        public int insertHocVienLV9(int HocVienID,
            //,bool boolNophocphiL9 ,DateTime dtNgayNophocphiL9,bool boolNophosoL9 ,DateTime dtNgaynophosoL9,
                                    DateTime dtNgayHoanThanhL9, string NoiDungHoanThanh, int NguoiDungID, int LevelID, int TrangThaiGoiID,
                                    string NoiDungTaiSao, int TrangThaiID)
        {
            int numAffected;
            // create the parameters
            SqlParameter[] parameters =  {	    new SqlParameter("@ID", SqlDbType.Int ,4),
                                                new SqlParameter("@HocVienID", SqlDbType.Int, 4),
                                                //new SqlParameter("@NophocphiL9", SqlDbType.Bit ,1),
                                                //new SqlParameter("@NgayNophocphiL9", SqlDbType.DateTime)	,	
                                                //new SqlParameter("@NophosoL9", SqlDbType.Bit, 1),
                                                //new SqlParameter("@NgaynophosoL9", SqlDbType.DateTime)	,
                                                new SqlParameter("@NgayHoanThanhL9", SqlDbType.DateTime)	,
                                                new SqlParameter("@NoiDungHoanThanh", SqlDbType.NVarChar ,512),
                                                new SqlParameter("@NguoiDungID", SqlDbType.Int, 4),
                                                new SqlParameter("@LevelID", SqlDbType.Int, 4),
                                                new SqlParameter("@TrangThaiGoiID", SqlDbType.Int, 4),	
                                                new SqlParameter("@NoiDungTaiSao", SqlDbType.NVarChar, 512),	
                                                new SqlParameter("@TrangThaiID", SqlDbType.Int, 4)		
										 };
            // set the values
            parameters[1].Value = HocVienID;
            //parameters[2].Value = boolNophocphiL9;
            //parameters[3].Value = dtNgayNophocphiL9;
            //parameters[4].Value = boolNophosoL9;
            //parameters[5].Value = dtNgaynophosoL9;
            parameters[6].Value = dtNgayHoanThanhL9;
            parameters[7].Value = NoiDungHoanThanh.Trim();
            parameters[8].Value = NguoiDungID;
            parameters[9].Value = LevelID;
            parameters[10].Value = TrangThaiGoiID;
            parameters[11].Value = NoiDungTaiSao;
            parameters[12].Value = TrangThaiID;
            parameters[0].Direction = ParameterDirection.Output;

            // run the procedure
            RunProcedure("sp_HocVienLV9_insertLV9Main", parameters, out numAffected, connec);

           // return (int)parameters[0].Value;
            return numAffected;
        }
        // Xoa Role
        public int removeHocVienLV9(int HocVienID)
        {
            int numAffected;
            // create the parameters
            SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int) };
            parameters[0].Value = HocVienID;
            // run the procedure
            RunProcedure("sp_HocVienLV9_removeLV9", parameters, out numAffected, connec);
            return numAffected;
        }
    }
}